/*
 * Copyright (c) Mirth Corporation. All rights reserved.
 * 
 * http://www.mirthcorp.com
 * 
 * The software in this package is published under the terms of the MPL license a copy of which has
 * been included with this distribution in the LICENSE.txt file.
 */

package com.mirth.connect.connectors.jdbc;

import java.util.List;
import java.util.Map;

import com.mirth.connect.donkey.model.message.ConnectorMessage;
import com.mirth.connect.donkey.server.ConnectorTaskException;

public interface DatabaseReceiverDelegate {
    public void deploy() throws ConnectorTaskException;

    public void undeploy() throws ConnectorTaskException;

    public void start() throws ConnectorTaskException;

    public void stop() throws ConnectorTaskException;

    /**
     * Execute the poll query and return an object representing the results
     * 
     * @return Either a ResultSet or List&lt;Map&lt;String, Object&gt;&gt;
     */
    public Object poll() throws DatabaseReceiverException, InterruptedException;

    /**
     * Run the post-process sql/script after polling is complete (if post-process is set to 'once'
     * in the UI) and perform any required clean up operations.
     */
    public void afterPoll() throws DatabaseReceiverException, InterruptedException;

    /**
     * Run the post-process sql/script after each message is processed (if post-process is set to
     * 'each' in the UI)
     * 
     * @param resultMap
     *            The result that was retrieved by the select query/script
     * @param mergedConnectorMessage
     *            The merged ConnectorMessage generated by the channel after processing (null if the
     *            channel is responding immediately and not waiting for the message to finish
     *            processing)
     */
    public void runPostProcess(Map<String, Object> resultMap, ConnectorMessage mergedConnectorMessage) throws DatabaseReceiverException, InterruptedException;

    /**
     * Run the post-process SQL/script once for all results.
     * 
     * @param resultsList
     *            The list of all results returned by the query/script
     * @param mergedConnectorMessage
     *            The merged ConnectorMessage generated by the channel after processing (null if the
     *            channel is responding immediately and not waiting for the message to finish
     *            processing)
     */
    public void runAggregatePostProcess(List<Map<String, Object>> resultsList, ConnectorMessage mergedConnectorMessage) throws DatabaseReceiverException, InterruptedException;
}
